package com.huaxin.device.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.huaxin.device.models.EquipmentDataSource;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface EquipmentDataSourceMapper extends BaseMapper<EquipmentDataSource> {
    /**
     * 根据配电房ID列表，统计每个配电房关联的采集设备数量（去重）
     *
     * @param roomIds 配电房ID列表
     * @return List<Map < String, Object>>，包含 room_id 和 count
     */
    @Select({
            "<script>",
            "SELECT room_id, COUNT(DISTINCT collector_id) AS count",
            "FROM equipment_data_source",
            "WHERE is_deleted = 0",
            "AND collector_id IS NOT NULL",
            "AND room_id IN",
            "<foreach item='id' collection='roomIds' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "GROUP BY room_id",
            "</script>"
    })
    @Results({
            @Result(column = "room_id", property = "room_id"),
            @Result(column = "count", property = "count")
    })
    List<Map<String, Object>> countCollectorsByRoomIds(@Param("roomIds") List<String> roomIds);
}